#!/bin/bash
###
 # @Author: dvlproad dvlproad@163.com
 # @Date: 2023-07-31 19:46:02
 # @LastEditors: dvlproad dvlproad@163.com
 # @LastEditTime: 2023-08-02 22:35:25
 # @FilePath: /AutoPackage-CommitInfo/bulidScriptCommon/personnel/personnelParamsJsonFile_deal.sh
 # @Description: 人员信息处理
### 
#sh personnelParamsJsonFile_deal.sh -personnelArgJsonF "${Product_Personnel_FILE_PATH}" -envJsonF "${ENVIRONMENT_FILE_PATH}"
#sh personnelParamsJsonFile_deal.sh -personnelArgJsonF "../example_packing_info/personnel_robot.json" -envJsonF "../example_packing_info/app_info.json"

#echo "===========进入脚本$0==========="

JQ_EXEC=`which jq`

# shell 参数具名化
show_usage="args: [-personnelArgJsonF, -envJsonF]\
                                  [--personnel-argument-json-file=, --environment-json-file=]"

while [ -n "$1" ]
do
        case "$1" in
                -personnelArgJsonF|--personnel-argument-json-file) Product_Personnel_FILE_PATH=$2; shift 2;;
                -envJsonF|-environment-json-file) ENVIRONMENT_FILE_PATH=$2; shift 2;;
                --) break ;;
                *) echo $1,$2,$show_usage; break ;;
        esac
done

# 当前【shell脚本】的工作目录
# $PWD代表获取当前路径，当cd后，$PWD也会跟着更新到新的cd路径。这个和在终端操作是一样的道理的
CurrentDIR_Script_Absolute="$( cd "$( dirname "$0" )" && pwd )"
#echo "CurrentDIR_Script_Absolute=${CurrentDIR_Script_Absolute}"
#bulidScriptCommon_dir_Absolute=${CurrentDIR_Script_Absolute}/..
bulidScriptCommon_dir_Absolute=${CurrentDIR_Script_Absolute%/*} # 使用此方法可以避免路径上有..
#echo "bulidScriptCommon_dir_Absolute=${bulidScriptCommon_dir_Absolute}"

qscript_path_get_filepath="${bulidScriptCommon_dir_Absolute}/qscript_path_get.sh"
qbase_update_json_file_singleString_script_path="$(sh ${qscript_path_get_filepath} qbase update_json_file_singleString)"

echo "Product_Personnel_FILE_PATH=${Product_Personnel_FILE_PATH}"
if [ ! -f "${Product_Personnel_FILE_PATH}" ];then
    echo "$0 ❌:您的$PWD/${Product_Personnel_FILE_PATH}文件不存在，请检查！"
    exit_script
fi

source ${bulidScriptCommon_dir_Absolute}/a_function.sh ${bulidScriptCommon_dir_Absolute} # 为了使用 updatePackageErrorCodeAndMessage
check_jsonFile_valid ${Product_Personnel_FILE_PATH}
if [ $? != 0 ]; then
    exit_script
fi
  

source ${bulidScriptCommon_dir_Absolute}/a_source_env.sh -appInfoF "${ENVIRONMENT_FILE_PATH}" # 获取 BRANCH\PlatformType\PackageTargetType\PackageNetworkType
echo "------PackageNetworkType:${PackageNetworkType}"


sh ${qbase_update_json_file_singleString_script_path} -jsonF "${ENVIRONMENT_FILE_PATH}" -k "productPersonnelJsonFile" -v "${Product_Personnel_FILE_PATH}"
